package game.module.user.processor;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import game.common.PlayingRoleMsgProcessor;
import game.entity.PlayingRole;
import game.module.user.bean.PlayerAddressBean;
import game.module.user.logic.PlayerDaoHelper;
import game.util.CommUtil;
import lion.common.MsgCodeAnn;
import lion.netty4.message.MyRequestMessage;
import lion.netty4.message.RequestMessageRaw;
import lion.netty4.message.RequestProtoMessage;
import lua.LuaMessageHall.C2SPlayerLocation;

/**
 * @author:Pomelo.lee
 * @date:2017年9月15日 下午4:57:51
 */
@MsgCodeAnn(msgcode = C2SPlayerLocation.id, accessLimit = 500)
public class PlayerLocationProcessor extends PlayingRoleMsgProcessor {

	private static Logger logger = LoggerFactory.getLogger(PlayerLocationProcessor.class);

	@Override
	public void process(PlayingRole playingRole, RequestMessageRaw requestMessage) throws Exception {
		C2SPlayerLocation req = C2SPlayerLocation.parse(requestMessage);
		int playerId = playingRole.getPlayerBean().getId();
		logger.info("player={},lat={},lng={},addr={}", playerId, req.lat, req.lng, playingRole.getGamePlayer().getAddress());
		PlayerAddressBean bean = new PlayerAddressBean();
		bean.setAddress(CommUtil.getIpAddr(playingRole.getGamePlayer().getAddress()));
		bean.setLat(req.lat);
		bean.setLng(req.lng);
		bean.setPlayerId(playerId);
		bean.setUpdateTime(new Date());
		PlayerDaoHelper.getInstance().asyncAddOrUpdateAddress(bean);
	}

	@Override
	public void processProto(PlayingRole playingRole, RequestProtoMessage request) throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void processWebsocket(PlayingRole playingRole, MyRequestMessage request) throws Exception {
		// TODO Auto-generated method stub

	}

}
